//
//  XJYTabBarController.m
//  ShopMall
//
//  Created by XJY on 17/1/17.
//  Copyright © 2017年 XinJinYing. All rights reserved.
//

#import "XJYTabBarController.h"
#import "XJYNavigationController.h"
@interface XJYTabBarController ()

//存储界面的数组
@property (nonatomic, strong) NSArray *viewControllerArray;


@end

@implementation XJYTabBarController

- (NSArray *)viewControllerArray
{
    if (!_viewControllerArray) {
        _viewControllerArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"XJYTabBarController" ofType:@"plist"]];
    }
    return _viewControllerArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupUI];
}

- (void)setupUI
{
    
    //获取tabbarItem的样式，才可以修改样式
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName : RGB(56, 165, 241)} forState:UIControlStateSelected];
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName : RGB(132, 132, 132)} forState:UIControlStateNormal];
    [self.tabBar setBackgroundImage:[UIImage imageNamed:@"tabbar_back"]];
    for (NSDictionary *dict in self.viewControllerArray) {
        Class viewControllerClass = NSClassFromString(dict[@"viewController"]);
        UIViewController *viewController = [[viewControllerClass alloc] init];
        viewController.tabBarItem.image = [UIImage imageNamed:dict[@"image"]];
        viewController.tabBarItem.selectedImage = [UIImage imageNamed:dict[@"selectImage"]];
        viewController.title = dict[@"title"];
        
        XJYNavigationController *navigationController = [[XJYNavigationController alloc] initWithRootViewController:viewController];
        
        [self addChildViewController:navigationController];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
